// Log.h: interface for the CLog class.
//Written by Owen Chen
//Data:2003/1/17
//Change Record:
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_LOG_H__6A7602DA_64B0_4963_9373_CD3A3B626AAB__INCLUDED_)
#define AFX_LOG_H__6A7602DA_64B0_4963_9373_CD3A3B626AAB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "osplatform.h"
#include "Semaphore.h"
#include "public.h"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#include "TSRollingLog.h"
#include "base.h"

#define LOG_TXT_MAX_LEN	1024000

#define	 LOG_ERROR		1

#ifdef LOG_WARNING
#undef	LOG_WARNING 
#endif

#define  LOG_WARNING	2
#define	 LOG_MSG		3

#ifdef LOG_DEBUG
#undef LOG_DEBUG
#endif
#define  LOG_DEBUG		4

#define	 LOG_MAX_LEVEL	4

class BASE_API CLog : public TSRollingLog
{
private:	
		CLog();
public:
		virtual ~CLog();
		static CLog& instance();
		void InitLog(char*inLogDir, char*inLogName, int inLevel, unsigned int inRollInDays = 0, unsigned int inMaxLogBytes = 0); 
		void SetLogLevel(int inLevel);

		virtual char* GetLogName() { return m_szLogName; }
		virtual char* GetLogDir()  { return m_szLogDirectory; }
		virtual UInt32 GetRollIntervalInDays() 	{ return m_uRollIntervalInDays; }
		virtual UInt32 GetMaxLogBytes()			{ return m_uMaxLogBytes; }
		int printf(int level,const int8 *format,...);
		void EnablePrintScreen(int bOn=1){m_bOn=bOn;}//enable/disable print console
private:
		char*			m_szLogName;
		char*			m_szLogDirectory;
		UInt32			m_uRollIntervalInDays;
		UInt32			m_uMaxLogBytes;
		char    m_szLogBuff[LOG_TXT_MAX_LEN];
		int		m_nLogLevel;
		CMutex  m_fMutex;
		int		m_bOn;

};
#define Loger	CLog::instance()


//extern BASE_API CLog	g_Log;
// Added for ldap operation log by Cliff on Oct. 23 2002
//#define INFO_D(info)   Loger.printf(LOG_MSG, "%s at %d : %s", THIS_FILE, __LINE__, (info))
//#define INFO1_D(format, info) 	Loger.printf(LOG_MSG, "%s at %d : "format, THIS_FILE, __LINE__, (info))
//#define INFO2_D(format, info1, info2) 	Loger.printf(LOG_MSG, "%s at %d : "format, THIS_FILE, __LINE__, (info1), (info2))
//#define INFO3_D(format, info1, info2, info3)  Loger.printf(LOG_MSG, "%s at %d : "format, THIS_FILE, __LINE__, (info1), (info2), (info3))
//		
//#define WARN_D(code, info)		Loger.printf(LOG_WARNING, "%s at %d : %s", THIS_FILE, __LINE__, (info))
//#define WARN1_D(code, format, info)		Loger.printf(LOG_WARNING, "%s at %d : "format, THIS_FILE, __LINE__, (info))
//#define WARN2_D(code, format, info1, info2)		Loger.printf(LOG_WARNING, "%s at %d : "format, THIS_FILE, __LINE__, (info1), (info2))
//#define WARN3_D(code, format, info1, info2, info3)	 Loger.printf(LOG_WARNING, "%s at %d : "format, THIS_FILE, __LINE__, (info1), (info2), (info3))
//
//#define ERROR_D(code, info)			Loger.printf(LOG_ERROR, "%s at %d : %s", THIS_FILE, __LINE__, (info))
//#define ERROR1_D(code, format, info)		Loger.printf(LOG_ERROR, "%s at %d : "format, THIS_FILE, __LINE__, (info))
//#define ERROR2_D(code, format, info1, info2)	Loger.printf(LOG_ERROR, "%s at %d : "format, THIS_FILE, __LINE__, (info1), (info2))
//#define ERROR3_D(code, format, info1, info2, info3)		Loger.printf(LOG_ERROR, "%s at %d : "format, THIS_FILE, __LINE__, (info1), (info2), (info3))
//
//#define INFO(info)      	Loger.printf(LOG_MSG, "%s", (info))
//#define INFO1(format, info) 		Loger.printf(LOG_MSG, ""format, (info))
//#define INFO2(format, info1, info2) 	Loger.printf(LOG_MSG, ""format, (info1), (info2))
//#define INFO3(format, info1, info2, info3) 		Loger.printf(LOG_MSG, ""format, (info1), (info2), (info3))
//		
//#define WARN(code, info)			Loger.printf(LOG_WARNING, "%s", (info))
//#define WARN1(code, format, info)			Loger.printf(LOG_WARNING, ""format, (info))
//#define WARN2(code, format, info1, info2)		Loger.printf(LOG_WARNING, ""format, (info1), (info2))
//#define WARN3(code, format, info1, info2, info3)			Loger.printf(LOG_WARNING, ""format, (info1), (info2), (info3))
//	
//#ifdef ERROR
//	#undef ERROR
//#endif
//#define ERROR(code, info)				Loger.printf(LOG_ERROR, "%s", (info))
//#define ERROR1(code, format, info)		Loger.printf(LOG_ERROR, ""format, (info))
//#define ERROR2(code, format, info1, info2)		Loger.printf(LOG_ERROR, ""format, (info1), (info2))
//#define ERROR3(code, format, info1, info2, info3)	Loger.printf(LOG_ERROR, ""format, (info1), (info2), (info3))
//

#endif // !defined(AFX_LOG_H__6A7602DA_64B0_4963_9373_CD3A3B626AAB__INCLUDED_)
